import Vue from 'vue'
import Router from 'vue-router'
// import store from '../store/store'
import NProgress from 'nprogress' //进度条
import 'nprogress/nprogress.css'

Vue.use(Router)
// 路由懒加载
const getComponent = (name, component) => () =>
    import(`@/views/${name}/${component}.vue`);
const myRouter = new Router({
    routes: [{
            path: '/index',
            name: 'index',
            component: getComponent('index', 'index'),
            meta: {
                title: '算法对抗挑战赛'
            },
            children: [{
                path: 'newLink',
                name: 'newLink',
                component: getComponent('newLink', 'newLink'),
                meta: {
                    title: '算法对抗挑战赛'
                }
            }]
        },
        {
            path: '/',
            redirect: '/index',
            meta: {
                title: '算法对抗挑战赛'
            }
        },
        {
            path: '/login',
            name: 'login',
            component: getComponent('login', 'login1'),
            meta: {
                title: '算法对抗挑战赛'
            },
        }
    ]
})

//判断是否存在token
myRouter.beforeEach((to, from, next) => {
    NProgress.start()
    // if (to.path !== '/login' && !store.state.token) {
    //     next('/login')
    //     NProgress.done() // 结束Progress
    // } else {
    //     next();
    // }
    // if (to.meta.roles) {
    //     to.meta.roles.includes(...store.getters.roles) ? next() : next('/404')
    // } else {
    //     next();
    // }
    next();
})

myRouter.afterEach(() => {
    NProgress.done() // 结束Progress
})
export default myRouter
